import { http } from "@/utils/http";
import { lmsUrlApi } from "../utils";

export type Knowledge = {
  id: string;
  name: string;
  describe: string;
  embeddingModel: string;
  chunkSize: number;
  chunkOverlap: number;
  creator: string;
  createdAt: string;
};

export type docEmbedding = {
  knowledgeId: string;
  coursewareIds: string[];
};

// 创建知识库
export const createKnowledge = (data: Knowledge) => {
  return http.request("post", lmsUrlApi("knowledge/create"), { data });
};
// 获取知识库列表
export const getKnowledgeList = (name: string) => {
  return http.request<Knowledge[]>("get", lmsUrlApi("knowledge/list"), {
    params: { name: name }
  });
};
// 删除知识库
export const deleteKnowledge = (id: string) => {
  return http.request("delete", lmsUrlApi("knowledge/" + id));
};

//文档嵌入
export const knowledgeEmbedding = (data: docEmbedding) => {
  return http.request("post", lmsUrlApi("knowledge/embedding"), { data });
};

export type StartChat = {
  knowledgeId: string;
  model: string;
  prom: string;
  query: string;
  temperature: number;
  referDocNum: number;
};
// 和llm聊天的接口
export const Chat = (data: StartChat) => {
  data.knowledgeId = "1790011348373999616";
  return http.request<any>(
    "post",
    lmsUrlApi("knowledge/chat"),
    { data },
    { timeout: 1000 * 1000 }
  );
};
